using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace DD
{
    public partial class ViewCart : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FillGrid();
            }
        }

        private void FillGrid()
        {
            DD.Visitors.Visitor vis = new DD.Visitors.Visitor();
            if (vis.IsLoggedIn())
            {

                DataTable dt = new DataTable();
                DataColumn c1 = new DataColumn("PRODUCTNAME");
                DataColumn c2 = new DataColumn("STYLE");
                DataColumn c3 = new DataColumn("QTY");
                DataColumn c4 = new DataColumn("UNIQUE_ID");
                dt.Columns.Add(c1);
                dt.Columns.Add(c2);
                dt.Columns.Add(c3);
                dt.Columns.Add(c4);




                DataSet ds = DD.ShoppingCart.CartManager.GetCartDS();


                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    DataRow iRow = dt.NewRow();
                    Products.Product p = Products.ProductManager.GetProduct((int)dr["PID"]);

                    iRow[0] = p.Name;
                    iRow[1] = dr["SID"].ToString();
                    iRow[2] = dr["QTY"].ToString();
                    iRow[3] = dr["UNIQUE_ID"].ToString();
                    dt.Rows.Add(iRow);

                }


                GRIDVIEW1.DataSource = dt;



                GRIDVIEW1.Columns[3].Visible = true;
                GRIDVIEW1.DataBind();
                GRIDVIEW1.Columns[3].Visible = false;
            }
        }



        protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow gr in GRIDVIEW1.Rows)
            {
                int UniqueId = Convert.ToInt32(gr.Cells[3].Text);
                TextBox tb = (TextBox)gr.FindControl("txtQTY");
                int qty = Convert.ToInt32(tb.Text);
                DD.ShoppingCart.CartManager.ChangeQty(UniqueId, qty);
                

            }
            FillGrid();
        }





    }
}
